import query from './atom/db/query';
import count from './atom/db/count';
import { IBaseTable } from './atom/db/interfaces';

declare const action_id: string;
declare const session_id: string;
declare const spaceid: string;

interface Message {
	filter: {};
	sort: {};
	page_size: number;
	page_no: number;
}

interface certifiInfo extends IBaseTable {
    incentive_type: string,
	staff_name: string
} 


async function atom(msg: Message) {
	const systemid = '6051';
	const { exec, prepare } = query(action_id, session_id, spaceid, systemid);
	const asc: string[] = [];
	const desc: string[] = [];
	if (msg.sort) {
		const key = Object.keys(msg.sort)[0];
		if (msg.sort[key] === -1) {
			desc.push(key);
		} else {
			asc.push(key);
		}
	}
	// 证照信息
	prepare('reward_punish_info', ['incentive_type', 'staff_name'], msg.filter, msg.page_size, msg.page_no, asc, desc);
	const [data] = await exec();


	const c = count(action_id, session_id, spaceid, systemid);
	c.prepare('reward_punish_info', msg.filter);
	const [t] = await c.exec();

	return { dataArray: data, count: t };
}